package com.example.mymatch.service.Imp;

import com.example.mymatch.dao.IWork;
import com.example.mymatch.model.Work;
import com.example.mymatch.service.IWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对服务接口规范的方法实现
 * 编写者：杨滢
 */

@Service
public class IWorkServiceImpl implements IWorkService{

    @Autowired
    private IWork workMapper;

    @Override
    public int insertWork(Work work){
        int workValue=0;
        //查看当前用户名称不能重复
        Work work1=new Work();
        work1.setWorkName(work.getWorkName());
        List<Work> getC=workMapper.getAllWork(work1);
        if (getC.size()>=1){
        //不可以添加用户名称
            workValue=-1;
        }else {
            workValue=workMapper.insertWork(work);
        }
        return workValue;
    }

    @Override
    public List<Work> getAllWork(Work work){
        return workMapper.getAllWork(work);
    }

    @Override
    public int updateWork(Work work){
        int workValue=0;
        //判断主键不能为0
        if (work.getId()!=0){
            //主键信息必修存在
            //名称不能重复
            workValue=workMapper.updateWork(work);
        }
        return workValue;
    }

    @Override
    public  int deleteWork(Work work){
        int workValue=0;
        //判断主键不能为0
        if (work.getId()!=0){
            //主键是否有其他表有关联，如果关联，则先删除其他表的信息，或者给出此条信息不允许被删除
            workValue=workMapper.deleteWork(work);
        }
        return workValue;
    }

    //单条查询
    @Override
    public Work getWork(Work work){
        Work work1=new Work();
        if (work.getId()!=0){
            work1=workMapper.getWork(work);
        }
        return work1;
    }
}
